package com.ki.erp.service.impl;

import com.ki.erp.constant.MongoStaticQueryConstant;
import com.ki.erp.req.GetStaticStatementReq;
import com.ki.erp.util.JsonToAggregationConverter;
import com.ki.erp.util.SpringBeanUtil;
import org.bson.Document;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ExcelServiceImpl {
    public void handle(GetStaticStatementReq req) throws Exception {
        MongoTemplate bean = SpringBeanUtil.getBean(MongoStaticQueryConstant.QUERY_DATABASE.get(req.getName()), MongoTemplate.class);

        List<Document> mappedResults = bean.aggregate(Aggregation.newAggregation(JsonToAggregationConverter.convert(MongoStaticQueryConstant.INSURANCE_ON_SALE)),
                MongoStaticQueryConstant.QUERY_COLLECTION.get(req.getName()),
                Document.class
        ).getMappedResults();
        List<List<String>> head = new ArrayList<>();
        mappedResults.get(0).keySet()
        mappedResults.stream().map(document -> {
            document.values().stream().toList();
        })

    }
}
